﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using GodPl.Utilities;

namespace GodPl.GameObjects.Creatures
{
    public class Drives
    {

        float[] values = new float[Enum.GetValues(typeof(DriveName)).Length];
        float sum = 0;
        Briyya briyya;

        public Briyya Briyya
        {
            get { return briyya; }
            set { briyya = value; }
        }

        public Drives(Briyya briyya)
        {
            this.briyya = briyya;
        }

        public float this[DriveName drive]
        {
            get { return values[(int)drive]; }
            set
            {
                values[(int)drive] = MathHelper.Clamp(value, 0f, 1f);
                updateSum();
            }
        }

        public float AsProbability(DriveName drive)
        {
            return (this[drive] / sum);
        }

        void updateSum()
        {
            sum = values.Sum();
        }


        public DriveName PickDominantDrive()
        {
            var items = Enum.GetValues(typeof(DriveName));
            var weights = from s in values
                                   select s;

            int index = GodPlGame.RandomGen.NextWeightedIndex(weights);

            return (DriveName)index;
        }


        public override string ToString()
        {
            string s = "{ ";
            foreach (DriveName v in Enum.GetValues(typeof(DriveName)))
            {
                s += v.ToString() + "=" + this[v] + " ";
            }

            s += "}";
            return s;
        }


        public float Hunger
        {
            get { return this[DriveName.Hunger]; }
        }

        public float SexDrive
        {
            get { return this[DriveName.SexDrive]; }
        }

        public float Tiredness
        {
            get { return this[DriveName.Tiredness]; }
        }

        public float Boredom
        {
            get { return this[DriveName.Boredom]; }
        }

        public float Pain
        {
            get { return this[DriveName.Pain]; }
        }

    }


    public enum DriveName
    {
        Hunger, Boredom, Fear, Pain, Tiredness, SexDrive
    }

}
